"""
URL configuration for TasteLink0 project.

The `urlpatterns` list routes URLs to views. For more information please see:
    https://docs.djangoproject.com/en/5.2/topics/http/urls/
Examples:
Function views
    1. Add an import:  from my_app import views
    2. Add a URL to urlpatterns:  path('', views.home, name='home')
Class-based views
    1. Add an import:  from other_app.views import Home
    2. Add a URL to urlpatterns:  path('', Home.as_view(), name='home')
Including another URLconf
    1. Import the include() function: from django.urls import include, path
    2. Add a URL to urlpatterns:  path('blog/', include('blog.urls'))
"""

from django.contrib import admin
from django.urls import path
from django.urls import path
from drf_spectacular.views import SpectacularAPIView, SpectacularRedocView, SpectacularSwaggerView
from rest_framework import views
from app.views.franchise_views import (
    SubmitFranchiseApplicationView,
    ListFranchiseApplicationsView,
    ApproveFranchiseApplicationView,
    GetMyFranchiseApplicationsView
)
from app.views.category_views import CreateCategoryView
from app.views.employee_views import CreateEmployeeView, GetEmployeeListView, UpdateEmployeeView, ClockInView, \
    ClockOutView, GetAttendanceRecordsView, SubmitLeaveRequestView, ApproveLeaveRequestView, RejectLeaveRequestView, \
    GetLeaveRequestsView, CalculateDailyPerformanceView, GetPerformanceRecordsView, CalculateSalaryView, \
    GetSalaryRecordsView,CreateEmployeeByUsernameView,RecordActivityView
from app.views.user_views import (
    LoginView,
    RegisterWithPhonePasswordView,
    RegisterWithWeChatOpenIdView,
    GetUserInfoView, CurrentUserInfoView,
)

from app.views.merchant_views import (
    RegisterMerchantView,
    UpdateMerchantInfoView,
    UpdateMerchantImagesView,
    GetMerchantInfoView,
    ListAllMerchantsView,
)

from app.views.dish_views import (
    UploadDishView,
    UpdateDishStockView,
    ListCategoriesWithDishesView,
    GetDishDetailView, PublicListCategoriesWithDishesView, PublicGetDishDetailView,
)

from app.views.order_views import (
    CreateOrderView,
    CancelOrderView,
    GetOrderDetailView,
    RateOrderView,
    ListUserOrdersView,
    GetPendingCookOrdersView,
    GetPendingServeOrdersView,
    

    # 商家相关
    ListMerchantOrdersView,
    CompleteOrderItemView,
    BatchCompleteOrderItemsView,
    CancelAllOrderItemsView, PayOrderView, ListPendingOrdersView, GetPendingDishesByCategoryView,
)
from app.views.employee_views import (
    # 员工认证
    
    # 订单管理
    
    
    
    # 员工活动
    RecordCookActivityView,
    RecordServeActivityView,
    
    # 员工信息
    GetCurrentEmployeeInfoView,
)
urlpatterns = [
    # =============================
    #  用户模块（需登录）
    # =============================
    path('user/info/<str:user_id>/', GetUserInfoView.as_view(), name='get_user_info'),
    path('info/me/', CurrentUserInfoView.as_view(), name='current_user_info'),

    # =============================
    #  订单模块 - 用户端（需登录：customer）
    # =============================
    path('order/create/', CreateOrderView.as_view(), name='create_order'),
    path('order/pay/<str:order_id>/', PayOrderView.as_view(), name='pay_order'),
    path('order/cancel/<uuid:order_id>/', CancelOrderView.as_view(), name='cancel_order'),
    path('order/detail/<uuid:order_id>/', GetOrderDetailView.as_view(), name='get_order_detail'),
    path('order/rate/<uuid:order_id>/', RateOrderView.as_view(), name='rate_order'),
    path('order/list/', ListUserOrdersView.as_view(), name='list_user_orders'),

    # =============================
    #  菜品模块 - 商家端（需登录：merchant）
    # =============================
    path('merchant/dish/upload/', UploadDishView.as_view(), name='upload_dish'),
    path('merchant/dish/update-stock/<uuid:dish_id>/', UpdateDishStockView.as_view(), name='update_dish_stock'),


    # =============================
    # 商家模块 - 商家端（需登录：merchant）
    # =============================
    path('public/merchant/register/', RegisterMerchantView.as_view(), name='register_merchant'),
    path('merchant/update-info/', UpdateMerchantInfoView.as_view(), name='update_merchant_info'),
    path('merchant/update-images/', UpdateMerchantImagesView.as_view(), name='update_merchant_images'),
    path('merchant/category/', CreateCategoryView.as_view(), name='create_category'),


    # =============================
    #  订单模块 - 商家端（需登录：merchant）
    # =============================
    path('merchant/order/list/', ListMerchantOrdersView.as_view(), name='list_merchant_orders'),
    path('merchant/dish/list/', ListCategoriesWithDishesView.as_view(), name='list_categories_with_dishes'),
    path('merchant/dish/detail/<uuid:dish_id>/', GetDishDetailView.as_view(), name='get_dish_detail'),
    path('merchant/order/item/complete/<int:item_id>/', CompleteOrderItemView.as_view(), name='complete_order_item'),
    path('merchant/order/item/batch-complete/<uuid:order_id>/', BatchCompleteOrderItemsView.as_view(), name='batch_complete_order_items'),
    path('merchant/order/item/cancel-all/<uuid:order_id>/', CancelAllOrderItemsView.as_view(), name='cancel_all_order_items'),
    path('merchant/order/pending/', ListPendingOrdersView.as_view(), name='list_pending_orders'),
    path('merchant/order/kitchen/', GetPendingDishesByCategoryView.as_view(), name='get_pending_dishes_by_category'),


    # =============================
    #  公共模块（无需登录）
    # =============================
    #  用户登录和注册接口
    path('public/user/login/', LoginView.as_view(), name='login'),
    path('public/user/register/phone/', RegisterWithPhonePasswordView.as_view(), name='register_with_phone'),
    path('public/user/register/wechat/', RegisterWithWeChatOpenIdView.as_view(), name='register_with_wechat'),

    #  商家公共信息接口
    path('public/merchant/list/', ListAllMerchantsView.as_view(), name='list_all_merchants'),
    path('public/merchant/info/<uuid:merchant_id>/', GetMerchantInfoView.as_view(), name='get_public_merchant_info'),
    path('public/merchant/<uuid:merchant_id>/dishes/', PublicListCategoriesWithDishesView.as_view(), name='list_categories_with_dishes'),
    path('public/merchant/<uuid:merchant_id>/<uuid:dish_id>/', PublicGetDishDetailView.as_view(), name='get_public_dish_detail'),


    # 员工管理（商家专用）
    path('merchant/employee/create/', CreateEmployeeView.as_view()),
    path('merchant/employee/update/<str:user_id>/', UpdateEmployeeView.as_view()),
    path('merchant/employee/list/', GetEmployeeListView.as_view()),
    path('merchant/employee/create-by-username/', CreateEmployeeByUsernameView.as_view(), name='create_employee_by_username'),

    # 考勤管理
    path('employee/clock-in/', ClockInView.as_view()),
    path('employee/clock-out/', ClockOutView.as_view()),
    path('employee/attendance/', GetAttendanceRecordsView.as_view()),

    # 请假管理
    path('employee/leave/submit/', SubmitLeaveRequestView.as_view()),
    path('merchant/leave/approve/<str:leave_id>/', ApproveLeaveRequestView.as_view()),
    path('merchant/leave/reject/<str:leave_id>/', RejectLeaveRequestView.as_view()),
    path('employee/leave/list/', GetLeaveRequestsView.as_view()),
    # =============订单状态管理============= #
    path('order/pending-cook/', GetPendingCookOrdersView.as_view(), name='get-pending-cook-orders'),
    path('order/pending-serve/', GetPendingServeOrdersView.as_view(), name='get-pending-serve-orders'),
    
    # =============员工活动记录============= #
    path('employee/cook/', RecordCookActivityView.as_view(), name='record-cook-activity'),
    path('employee/serve/', RecordServeActivityView.as_view(), name='record-serve-activity'),

    # 绩效和薪资管理
    path('merchant/performance/calculate/', CalculateDailyPerformanceView.as_view()),
    path('merchant/performance/<str:user_id>/', GetPerformanceRecordsView.as_view()),
    path('merchant/salary/calculate/', CalculateSalaryView.as_view()),
    path('salary/records/', GetSalaryRecordsView.as_view()),

    path('user/franchise/apply/', SubmitFranchiseApplicationView.as_view(), name='submit_franchise_application'),
    
    # 管理员查看所有申请列表
    path('franchise/applications/', ListFranchiseApplicationsView.as_view(), name='list_franchise_applications'),
    
    # 管理员审批申请
    path('franchise/applications/<uuid:application_id>/approve/', ApproveFranchiseApplicationView.as_view(), name='approve_franchise_application'),
    
    # 用户查看自己的申请
    path('user/franchise/my-applications/', GetMyFranchiseApplicationsView.as_view(), name='get_my_franchise_applications'),

    # =============================
    #  管理后台入口
    # =============================
    path('admin/', admin.site.urls),


# 自动生成 OpenAPI Schema
    path('api/schema/', SpectacularAPIView.as_view(), name='schema'),

    # Swagger UI（可视化 API 页面）
    path('api/swagger/', SpectacularSwaggerView.as_view(url_name='schema'), name='swagger-ui'),

    # ReDoc UI（另一个好看的文档风格）
    path('api/redoc/', SpectacularRedocView.as_view(url_name='schema'), name='redoc'),
]

